
#include "msg_fes_broadcast.h"
#include "client_mgr.h"
#include "frontend_service.h"

extern NLNET::CCallbackServer *Clients;
extern NLNET::CMessage        msgout;

using namespace FES;

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// SERVICE IMPLEMENTATION /////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////

void cbTransport2Client ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);

	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	uint32 subSize;
	msgin.serial(subSize);
	msgin.lockSubMessage(subSize);

	msgout.clear();
	msgout.assignFromSubMessage(msgin);

	msgin.unlockSubMessage();
	Clients->send( msgout, pClient->con );
}

void cbTeamPlayerExit ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);

	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	uint8 roomidx;
	msgin.serial(roomidx);

	msgout.clear();
	msgout.setType("PE");
	msgout.serial(roomidx);

	Clients->send( msgout, pClient->con );
}


void cbTeamMasterInfo ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);

	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	uint8 roomidx;
	msgin.serial(roomidx);

	msgout.clear();
	msgout.setType("MI");
	msgout.serial(roomidx);

	Clients->send( msgout, pClient->con );
}

void cbGameStartFail ( NLNET::CMessage& msgin, const std::string &serviceName, NLNET::TServiceId serviceId )
{
	DEF::UID id;
	msgin.serial(id);
	
	CClient* pClient = ClientMgr.findClient(id);

	if(pClient==NULL)	{return;}

	msgout.clear();
	msgout.setType("RS_F");
	Clients->send( msgout, pClient->con );
}



